<template>
  <div id="backboneTeamEacht" ref="backboneTeamEacht" class="bt-eacht"></div>
</template>

<script>
export default {
  props: {
    eachtData: {
      default: () => {},
      type: Object,
    },
    isDialog: {
        type: Function,
        default: null
      },
    dData:{}
  },
  data() {
    return {};
  },
  components: {},
  mounted() {
    // this.echartsInit();
  },
  beforeDestroy() {},
  methods: {
    
    echartsInit() {
     
      let yData = this.eachtData.xData;
     
      // let xData = [10, 10, 9, 12, 9, 13, 13];
      let xData = this.eachtData.yData;
      console.log(this.eachtData, "====");
      let max = Math.max(...xData) + 5;
      let bgData = [300, 300, 300, 300, 300, 300, 300];
      let that = this;
      let option={
        grid: {
          left: "5%",
          right: "5%",
          bottom: "5%",
          top: "15%",
          containLabel: true,
        },

        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "none",
          },
          formatter: function (params) {
            return (
              params[0].name +
              "<br/>" +
              "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:rgba(74,202,150,0.9)'></span>" +
             '高素能骨干团队' +
              // params[0].seriesName +
              " : " +
              params[0].value +
              "人<br/>"
            );
          },
        },
        xAxis: {
          show: true,
          type: "value",
          // splitNumber: 3,
          // splitNumber: 50,
          max: max,
          axisLabel: {
            show: true,

            textStyle: {
              color: "#fff",
              fontSize: 10,
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              width: 0.5,
              type: "dotted",
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false,
          },
        },
        yAxis: [
          {
            type: "category",
            boundaryGap: false,
            inverse: true,
            axisLabel: {
              show: true,
              textStyle: {
                color: "#fff",
                fontSize: 10,
              },
            },
            splitLine: {
              show: false,
            },
            axisTick: {
              show: true,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#6a9084",
              },
            },
            data: yData,
          },
          {
            type: "category",
            inverse: true,
            boundaryGap: false,
            data: xData,
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#2C3F58",
                width: 0, //这里是为了突出显示加上的
              },
            },
            axisLabel: {
              show: true,
              inside: false,
              textStyle: {
                color: "#ffffff",
                fontSize: 10,
              },
              // formatter: function (val) {
              //   return val;
              // },
            },
          },
        ],

        series: [
          {
            name: "省级高素能骨干团队",
            type: "bar",
            zlevel: 1,
            itemStyle: {
              normal: {
                // barBorderRadius: [0, 11, 11, 0],
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "#309dc4" },
                  { offset: 0.5, color: "#36adcd" },
                  { offset: 1, color: "#3cbad3" },
                ]),
              },
            },
            barWidth: 9,
            data: xData,
          },
          {
            name: "背景",
            type: "bar",
            barWidth: 9,
            barGap: "-100%",
            data: bgData,
            itemStyle: {
              normal: {
                color: "#123474",
                barBorderRadius: 0,
              },
            },
          },
        ],
      }
      let myChart = this.$echarts.init(this.$refs.backboneTeamEacht);
      myChart.off('click')
        myChart.on('click', function (event) {
          if (event.data) {
            that.isDialog(event.name);
          }
        });
        myChart.clear();
      myChart.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped>
.bt-eacht {
  width: 100%;
  height: 100%;
}
</style>
